const computedBehavior = require('miniprogram-computed').behavior

const classPrefix = 'mp-'

function create(name, options) {
  if (!options) throw new Error('Component options is missing.')

  // options.addGlobalClass = true

  options.data = Object.assign(
    {
      classPrefix: classPrefix + name,
    },
    (options.data = options.data || {})
  )

  options.externalClasses = ['klass', ...(options.externalClasses = options.externalClasses || [])]

  options.behaviors = [computedBehavior, ...(options.behaviors = options.behaviors || [])]

  options.methods = Object.assign(
    {
      noop() {},
    },
    (options.methods = options.methods || {})
  )

  return Component(options)
}

module.exports = {
  create,
}
